<template>
	<view>
		<view class="top">
			<searchTemp class="search" @childByValue="searchyx"></searchTemp>
		</view>
		<view class="tiaojian">
			<view :class="id==item.id?'active':''" v-for="item in xuanze" :key="item.id" @click="fresh(item.id)">
				{{item.item}}
			</view>
		</view>
		<!-- <view class="label-item" :class="{'selected':item.isSelect}" v-for="(item,index) in productTagList" :key="index" v-bind:value="item.tagId" @click="toSelectTag(item)">{{item.tagName}}</view> -->
		
		<view class="dingdan-box" v-for="(obj,index) in yuyueList">
			<view class="dingdan-item" @click="toLiuCheng(obj)">
				<image class="touxiang" src="http://ai.ylcaifu.com/appimg/images/5.0-%E6%88%91%E7%9A%84-%E7%90%86%E8%B4%A2%E5%B8%88/5.3.1.0-%E6%88%91%E7%9A%84%E8%AE%A2%E5%8D%95-%E7%90%86%E8%B4%A2%E5%B8%88/android/drawable-xhdpi/tpuxiang.png"
				 mode=""></image>
				<view class="dingdan-right">
					<view class="dingdan-item-left">
						<view class="name">{{obj.custname}}</view>
						<view class="name" style="display: none;">{{obj.custid}}</view>
						<view class="name" style="display: none;">{{obj.yuyueNo}}</view>
						<view class="product-name">{{obj.pROD_NAME}}</view>
						<view class="jiaqian">
							￥{{obj.balance}}<span v-if="id==1"> 元</span><span v-if="id==2">元</span><span v-if="id==3">{{obj.unit}}</span>
						</view>
					</view>
					<view class="dingdan-item-right">
						<view :class="obj.status=='已到期'?'is-daoqi daoqi':'is-daoqi weidaoqi'">{{obj.status}}</view>
						<view v-if="id==1" class="time">{{obj.dakuanDate}}</view>
						<view v-if="id==2" class="time">{{obj.yuyueDate}}</view>
						<view v-if="id==3" class="time">{{obj.endDate}}</view>
					</view>
					<!-- <view class="dingdan-item-right">
						<view class="is-daoqi daoqi">已到期</view>
						<view class="time">2108-10-10</view>
					</view> -->
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import searchTemp from '../../../components/search-temp.vue'
	import global_wyx from '../../../components/tool/licaishiwyx'
	export default {
		components: {
			searchTemp
		},
		data() {
			return {
				id: 1,
				xuanze: [{
					item: "交易",
					id: 1
				}, {
					item: "预约",
					id: 2
				}, {
					item: "赎回",
					id: 3
				}],
				token:uni.getStorageSync('token_key'),
				yuyueList:[],
				custname:''
			};
		},
		onLoad() {
			uni.setStorageSync('searchPlaceholderText','请输入客户名称或产品名称');
			this.fresh(1)//展示交易
		},
		methods: {
			toLiuCheng(item){
				var isSimu = item.isSimu;
				var projid = item.projid;
				var custname = item.custname;
				var custid = item.custid;
				var yuyueNo = item.yuyueNo;
				var pROD_NAME = item.pROD_NAME;
				var balance = item.balance;
				if(balance!=null&&balance!="null"){
					var balanceStr = balance.replace(/,/g,"");
					console.info("balanceStr"+balanceStr)
					balance = parseInt(balanceStr)/10000;
				}
				if(this.id==2){
					if(isSimu=='1'){
						uni.navigateTo({
							url: '../../product/productYemian/productDetail/simuYuyue/simuYuyue?projId='+projid+'&proName='+pROD_NAME+'&balance='+balance+'&custid='+custid+'&custname='+custname+'&yuyueId='+yuyueNo,
							success: res => {},
							fail: () => {},
							complete: () => {}
						});
					}else if(isSimu=='0'){
						uni.navigateTo({
							url: '../../product/productYemian/productDetail/simuYuyue/baoliYuyue?projId='+projid+'&proName='+pROD_NAME+'&balance='+balance+'&custid='+custid+'&custname='+custname+'&yuyueId='+yuyueNo,
							success: res => {},
							fail: () => {},
							complete: () => {}
						});
					}
					
				}
			},
			searchyx(custname){
				console.info(custname)
				if(this.custname!=custname){
					this.custname = custname;
					this.fresh(this.id) 
				}
			},
			fresh(id) {
				this.id = id
				if(id==1){this.jiaoyi()}
				if(id==2){this.yuyue()}
				if(id==3){this.shuhui()}
			},
			jiaoyi(){//交易
				uni.request({
					url: global_wyx.api.wodeDingdan_jiaoyi,
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						token:this.token,
						custname:this.custname
					},
					success: res => {
						var getDate = res.data.data;
						console.info(getDate)
						this.yuyueList = [];
						for(var i=0;i<getDate.length;i++){
							var userInfo = new Object();
							userInfo.custname = getDate[i].custname;//姓名
							userInfo.pROD_NAME = getDate[i].pROD_NAME;//姓名
							userInfo.custid = getDate[i].custid;//id
							userInfo.status = getDate[i].sts;//status
							userInfo.cust_url = getDate[i].cust_url;//头像路径
							userInfo.yuyueNo = getDate[i].yuyueNo;//预约编号
							userInfo.yuyueDate = getDate[i].yuyueDate;//预约日期
							userInfo.sys_form = getDate[i].sys_form;//来源
							userInfo.balance = getDate[i].balance;//预约金额
							userInfo.dakuanDate = getDate[i].dakuanDate;//打款日期 
							this.yuyueList.push(userInfo);
							
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			yuyue(){
				uni.request({
					url: global_wyx.api.wodeDingdan_yuyue,
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						token:this.token,
						custname:this.custname
					},
					success: res => {
						var getDate = res.data.data;
						console.info(getDate)
						this.yuyueList = [];
						for(var i=0;i<getDate.length;i++){
							var userInfo = new Object();
							userInfo.custname = getDate[i].custname;//姓名
							userInfo.pROD_NAME = getDate[i].pROD_NAME;//姓名
							userInfo.custid = getDate[i].custid;//id
							userInfo.status = getDate[i].sts;//status
							userInfo.cust_url = getDate[i].cust_url;//头像路径
							userInfo.yuyueNo = getDate[i].yuyueNo;//预约编号
							userInfo.yuyueDate = getDate[i].yuyueDate;//预约日期
							userInfo.sys_form = getDate[i].sys_form;//来源
							userInfo.balance = getDate[i].balance;//预约金额
							userInfo.isSimu = getDate[i].isSimu;//0不是私募，1，是私募
							userInfo.projid = getDate[i].projid;//产品编号
							this.yuyueList.push(userInfo);
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			shuhui(){
				uni.request({
					url: global_wyx.api.wodeDingdan_shuhui,
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						token:this.token,
						custname:this.custname
					},
					success: res => {
						var getDate = res.data.data;
						console.info(getDate)
						this.yuyueList = [];
						for(var i=0;i<getDate.length;i++){
							var userInfo = new Object();
							userInfo.custname = getDate[i].custname;//姓名
							userInfo.pROD_NAME = getDate[i].pROD_NAME;//姓名
							userInfo.custid = getDate[i].custid;//id
							userInfo.status = getDate[i].sts;//status
							userInfo.cust_url = getDate[i].cust_url;//头像路径
							userInfo.yuyueNo = getDate[i].yuyueNo;//预约编号
							userInfo.endDate = getDate[i].endDate;//预约日期
							userInfo.sys_form = getDate[i].sys_form;//来源
							userInfo.balance = getDate[i].balance;//预约金额
							userInfo.unit = getDate[i].unit;
							console.info("userInfo.unit"+userInfo.unit)
							this.yuyueList.push(userInfo);
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>
	.tiaojian {
		display: flex;
		flex-direction: row;
		background: #FFFFFF;
		height: 40px;
		align-items: center;
		text-align: center;
		justify-content: space-around;
	}

	.tiaojian view {
		line-height: 37px;
		color: rgba(153, 153, 153, 1);

	}

	.tiaojian .active {
		border-bottom: 3px solid #c49c5a;
		color: rgba(196, 156, 90, 1);
	}

	.dingdan-box {

		background: rgb(255, 255, 255);
		padding: 0 30upx;
	}

	.dingdan-item {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		height: 89px;
		border-bottom: 1px solid rgba(238, 238, 238, 1);
	}

	.touxiang {
		height: 60px;
		width: 60px;
		margin-right: 30upx;
	}

	.dingdan-right {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;


		flex: 1;
	}

	.name {
		font-size: 16px;
		font-weight:bold;
	}
	.product-name{
		font-size: 12px;
		color: rgba(153,153,153,1);
	}
	.jiaqian {
		color:rgba(196,156,90,1);
		font-size: 13px;
	}

	.is-daoqi {
		text-align: center;

		border-radius: 22px;
		line-height: 22px;
	}

	.daoqi {
		border: 1px solid rgba(221, 221, 221, 1);
		color: rgba(221, 221, 221, 1);
	}

	.weidaoqi {
		border: 1px solid rgba(196, 156, 90, 1);
		color: rgba(196, 156, 90, 1);
	}

	.time {
		color: rgba(153, 153, 153, 1);
		line-height: 30px;
	}
</style>
